<template>
  <aside class="sidebar">
    <div class="storage-info">
      <div class="storage-header">
        <img :src="userInfo.avatar" alt="用户头像" class="sidebar-avatar" />
        <div class="user-details">
          <div class="sidebar-user-name">{{ userInfo.name }}</div>
          <div class="storage-text">
            已用 {{ userInfo.storage.used }}GB / {{ userInfo.storage.total }}GB
          </div>
        </div>
      </div>
      <div class="storage-progress">
        <div class="progress-bar" :style="{ width: userInfo.storage.percentage + '%' }"></div>
      </div>
      <button class="upgrade-btn">升级存储空间</button>
    </div>

    <div class="nav-menu">
      <ul>
        <li
            v-for="menu in navMenus"
            :key="menu.id"
            :class="{ active: menu.active }"
            @click="handleMenuClick(menu)"
        >
          <FontAwesomeIcon :icon="['fas', menu.icon]" />
          <span>{{ menu.text }}</span>
        </li>
      </ul>
    </div>
  </aside>
</template>

<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { UserInfo, NavMenu } from '@/stores/counter';

// 定义接收的属性
const props = defineProps<{
  userInfo: UserInfo;
  navMenus: NavMenu[];
}>();

// 定义向外发送的事件
const emit = defineEmits(['menu-click']);

// 处理菜单点击
const handleMenuClick = (menu: NavMenu) => {
  emit('menu-click', menu);
};
</script>

<style scoped>
/* 侧边栏 */
.sidebar {
  width: 240px;
  background-color: rgba(20, 20, 30, 0.6);
  border-radius: 8px;
  padding: 20px;
  margin-right: 15px;
  backdrop-filter: blur(5px);
  border: 1px solid rgba(134, 3, 174, 0.1);
  box-shadow: 0 0 15px rgba(134, 3, 174, 0.1);
}

.storage-info {
  margin-bottom: 30px;
}

.storage-header {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
  border: 2px solid rgba(134, 3, 174, 0.3);
}

.sidebar-user-name {
  color: #ffffff;
  font-weight: bold;
}

.storage-text {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.storage-progress {
  height: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  margin-bottom: 15px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #c084fc);
  border-radius: 4px;
  transition: width 0.5s;
}

.upgrade-btn {
  width: 100%;
  background: linear-gradient(135deg, #7c3aed, #a17fe0);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 0;
  cursor: pointer;
  transition: all 0.3s;
}

.upgrade-btn:hover {
  background: linear-gradient(135deg, #8b5cf6, #c084fc);
  box-shadow: 0 0 15px rgba(134, 3, 174, 0.5);
}

.nav-menu ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-menu li {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 5px;
  color: rgba(255, 255, 255, 0.7);
  transition: all 0.3s;
}

.nav-menu li.active {
  background-color: rgba(134, 3, 174, 0.2);
  color: #c084fc;
}

.nav-menu li:hover {
  background-color: rgba(134, 3, 174, 0.1);
  color: #ffffff;
}

.nav-menu li svg {
  margin-right: 10px;
}

/* 响应式设计 */
@media (max-width: 900px) {
  .sidebar {
    width: 100%;
    margin-right: 0;
    margin-bottom: 15px;
  }
  
  .nav-menu ul {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
  }
  
  .nav-menu li {
    flex: 1;
    min-width: 120px;
    justify-content: center;
  }
}
</style> 